package primary;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 日历
 */
public class L_Calendar {
    public static void main(String[] args) throws ParseException {
        Calendar calendar = new GregorianCalendar(Locale.CHINESE);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println("year=" + year + " month=" + month);

        System.out.println("--------- 请输入日期（格式为： 年-月-日）-----------");
        Scanner sc = new Scanner(System.in);
        String dateStr = sc.nextLine();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = sf.parse(dateStr);
        calendar.setTime(date);
        int nowDay = calendar.get(Calendar.DAY_OF_MONTH);
        System.out.println("sun\tmon\ttue\twes\tthu\tfri\tsut");
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        for (int i = 0; i < calendar.get(Calendar.DAY_OF_WEEK) - 1; i++) {
            System.out.print("\t");
        }
        int totalDays = calendar.getActualMaximum(Calendar.DATE);
        for (int i = 0; i < totalDays; i++) {
            if (nowDay == calendar.get(Calendar.DAY_OF_MONTH))
                System.out.print(calendar.get(Calendar.DAY_OF_MONTH) + "*" + "\t");
            else
                System.out.print(calendar.get(Calendar.DAY_OF_MONTH) + "\t");
            if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) System.out.println();
            calendar.add(Calendar.DAY_OF_MONTH, 1);
        }
    }
}
